package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bignerdranch.android.ecar.Bean.FaultBean;
import com.bignerdranch.android.ecar.R;

import java.util.List;

/**
 * Created by Administrator on 2016/7/19.
 */
public class FaultAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<FaultBean> mData;

    public FaultAdapter(Context context, List<FaultBean> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = mInflater.inflate(R.layout.fault_item,null);
        }
        ViewHold hold = new ViewHold();
        if (convertView.getTag()==null){
            hold.license = (TextView) convertView.findViewById(R.id.license);
            hold.status = (TextView) convertView.findViewById(R.id.status);
            hold.car_type = (TextView) convertView.findViewById(R.id.car_type);
            hold.count = (TextView) convertView.findViewById(R.id.count);
            hold.money = (TextView) convertView.findViewById(R.id.money);
            hold.point = (TextView) convertView.findViewById(R.id.point);

            convertView.setTag(hold);
        }else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.license.setText(mData.get(position).getLicense());
        hold.status.setText(mData.get(position).getStatus());
        hold.car_type.setText(mData.get(position).getCar_type());
        hold.count.setText(mData.get(position).getCount());
        hold.money.setText(mData.get(position).getMoney());
        hold.point.setText(mData.get(position).getPoint());

        return convertView;
    }

    private static class ViewHold {
        private TextView license;
        private TextView status;
        private TextView car_type;
        private TextView count;
        private TextView money;
        private TextView point;

    }
}
